import Cookies from 'js-cookie'
import store from '@/store'
// TOKEN 的 KEY值
const TokenKey = 'Token'

// Token
export function getToken() {
    return Cookies.get(TokenKey)
}

export function setToken(token, time) {
    return Cookies.set(TokenKey, token, { expires: time })
}

// 用户信息
export function removeToken() {
    return Cookies.remove(TokenKey)
}

export function getUserInfo() {
    const userInfo = localStorage.getItem('userInfo') ? localStorage.getItem('userInfo') : { fullName: '未知' }
    store.commit('user/SET_USERINFO', JSON.parse(userInfo))
    return userInfo
}

export function setUserInfo(userInfo) {
    localStorage.setItem('userInfo', JSON.stringify(userInfo))
    return
}

// 登录名
export function getUserName() {
    return localStorage.getItem('userName') ? localStorage.getItem('userName') : ''
}

export function setUserName(userName) {
    return localStorage.setItem('userName', userName)
}

export function removeUserName() {
    return localStorage.removeItem('userName')
}